package cz.muni.fi.pa165.business.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * ForestVisit represents an m-n relation between Forest and Picker entities.
 * Besides setting Forest and Picker objects it allows date and description of a
 * visit to be specified.
 *
 * @author Matej Cimbora
 */
@Entity
public class ForestVisit implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    /**
     * Picker object representing a visitor
     */
    @ManyToOne
    private Picker picker;
    /**
     * Forest object representing location of the visit
     */
    @ManyToOne
    private Forest forest;
    /**
     * Date of the visit
     */
    @Temporal(TemporalType.DATE)
    private Date dateOfVisit;
    /**
     * Text description of a visit
     */
    private String description;
    /**
     * List of mushrooms found during the visit Key is Mushroom, Value is amount
     * of this mushrooms
     */
    @ManyToMany(fetch = FetchType.EAGER)
    private List<Mushroom> mushroomsFound;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Picker getPicker() {
        return picker;
    }

    public void setPicker(Picker picker) {
        this.picker = picker;
    }

    public Forest getForest() {
        return forest;
    }

    public void setForest(Forest forest) {
        this.forest = forest;
    }

    public Date getDateOfVisit() {
        return dateOfVisit;
    }

    public void setDateOfVisit(Date dateOfVisit) {
        this.dateOfVisit = dateOfVisit;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<Mushroom> getMushroomsFound() {
        return mushroomsFound;
    }

    public void setMushroomsFound(List<Mushroom> mushroomsFound) {
        this.mushroomsFound = mushroomsFound;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ForestVisit)) {
            return false;
        }
        ForestVisit other = (ForestVisit) object;
        if ((this.id == null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ForestVisit[ id=" + id + ", " + forest + ", " + picker
                + ", " + dateOfVisit + ", " + description + " ]";
    }
}
